var EventEmitter = require('events').EventEmitter; // 用以事件提交
var assign = require('object-assign'); // 对象深层合并


var ListStore = assign({},EventEmitter.prototype,{
	items:[],
	
	getAll:function(){
		return this.items;
	},
	
	addNewItemHandler:function(text){
		this.items.push(text);
	},

	removeItemHandler:function(index){
		console.log('Stroe',index);
		this.items.splice(index,1);
	},
	//emitChange才是真正的提交添加操作
	emitChange:function(){
		this.emit('change');
	},
	//事件的监听
	addChangeListener:function(callback){
		this.on('change',callback)
	},
	//监听的移除
	removeChangeListener:function(callback){
		this.removeListener('change',callback);
	}
})

module.exports = ListStore;